package com.pw.demo3.service.impl;

import com.pw.demo3.bean.Employee;
import com.pw.demo3.mapper.EmployeeMapper;
import com.pw.demo3.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return employeeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Employee record) {
        return employeeMapper.insert(record);
    }

    @Override
    public Employee selectByPrimaryKey(Long id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public Employee selectByName(String name) {
        return employeeMapper.selectByName(name);
    }

    @Override
    public List<Employee> selectAll() {
        return employeeMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Employee record) {
        return employeeMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Employee> selectByExample(String key, String deptId) {
        if (key!=null&&key!=""){
            key = "%" + key + "%";
            return employeeMapper.selectByKeyWord(key);
        }else if (deptId.equals("-1")) {
            return employeeMapper.selectAll();
        }else if(!deptId.equals("-1")){
            int id=Integer.parseInt(deptId);
            return employeeMapper.selectByDeptId(id);
        }
        return employeeMapper.selectAll();
    }
}